package com.example.esskill;

/**
 * ClassName: Hanoi <br/>
 * Description: <br/>
 * date: 2024/2/5 16:22<br/>
 *
 * @author LXC<br />
 * @since JDK 1.8
 */
import java.util.Scanner;

public class Hanoi {
    static int count = 1;
    public static void main(String[] args) throws InterruptedException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入汉诺塔盘数:>");
        int n = scanner.nextInt();
        hanoi(n, 'A', 'B', 'C');
    }

    public static void hanoi(int nDisks, char A, char B, char C) throws InterruptedException {
        if (1 == nDisks) {
            move(nDisks, A, C);
            return;
        }
        hanoi(nDisks - 1, A, C, B);
        move(nDisks, A, C);
        hanoi(nDisks - 1, B, A, C);
    }


    public static void move(int nDisks, char sourceTower, char destTower) throws InterruptedException {
      //  Thread.sleep(1000);
        System.out.println("编号为" + nDisks + "的盘子正在从" + sourceTower + "移动到" + destTower+"---------------->"+count++);
    }
}


